/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lab07;

import java.util.Random;

/**
 * A car unit that is threadable.
 * @author Johnny
 */
public class Auto extends Thread {
  public static final int N = 50;
  public static boolean stop = false;

  private RaceCanvas parent;
  private int id;

  public Auto(int id, RaceCanvas parent) {
    this.id = id;
    this.parent = parent;
  }

  @Override
  public void run() {
    Random r = new Random();
    for (int i=1; i<N && !Auto.stop; i++) {
      try {
        sleep((r.nextInt(3)+1)*100);
      }
      catch (InterruptedException e) { }
      parent.setPos(id, i);
    }
  }
}
